package view;


import java.awt.Frame;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.util.Observable;
import java.util.Observer;

import model.TemperatureModel;

public abstract class SliderView implements Observer {
	protected Scrollbar tempControl;
	protected TemperatureModel modelT = null;
	protected Frame sliderFrame;
	
	public SliderView() {
		sliderFrame = new Frame("SliderView");
	}
	
	public void initialize(int h, int v, TemperatureModel model, int rangeBegin, int rangeEnd){
		model.addObserver(this); 
		this.modelT = model;
		tempControl = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, rangeBegin, rangeEnd);
		sliderFrame.add(tempControl);
		sliderFrame.setSize((int) 2*Math.abs(rangeBegin-rangeEnd), 50);
		sliderFrame.setLocation(h, v);
		sliderFrame.setVisible(true);
		sliderFrame.addWindowListener(new TemperatureView.CloseListener());
		update(modelT, null);
	}
	
	public void setAdjustmentListener(AdjustmentListener sliderListener) {
		tempControl.addAdjustmentListener(sliderListener);

	}
	
	public int getTempValue() {
		return tempControl.getValue();
	}
}
